from django.db import models


# Create your models here.
class DateTimeModelMixin(models.Model):  # 类名可以自定义 但继承类不可改
    # 自定义的创建时间和修改时间的扩展类
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)

    class Meta:
        abstract = True  # 抽象模型类 迁移不会去创建对应的表而只会用于扩展,让其它的模型类来继承


class IsDeleteModelMixin(models.Model):  # 专门来处理逻辑删除的类
    # 自定义逻辑删除的扩展类
    is_delete = models.BooleanField('逻辑删除', default=False, help_text='逻辑删除')

    # 重写delete方法，实现逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()

    class Meta:
        abstract = True


class ModelSetMixin(DateTimeModelMixin, IsDeleteModelMixin):
    # 自定义整合的模型扩展类

    class Meta:
        abstract = True